package com.jwiki.app.jkeeper.controller;

import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.jwiki.app.jkeeper.common.data.Context;
import com.jwiki.app.jkeeper.common.data.Response;

public abstract class BaseController {

    public static Context getContext() {
        RequestAttributes request = RequestContextHolder.currentRequestAttributes();
        if (request != null) {
            if (request instanceof ServletRequestAttributes) {
                HttpSession session = ((ServletRequestAttributes) request).getRequest().getSession();
                if (session != null) {
                    Context context = (Context) session.getAttribute(Context.AUTH_INFO_KEY);
                    if (context != null) {
                        return context;
                    }
                }
            }
        }
        return new Context();
    }

    protected Response getResponse() {
        return new Response();
    }

}
